查看原文
其他

使用Kubeadm快速部署Kubernetes(二)

2017-03-24 Mike 运维之美

安装flannel pod网络

Kubernetes一共提供五种网络组件,可以根据自己的需要选择。要使用Flannel网络,因此我们需要执行如下安装命令:

$ kubectl apply -f  https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml serviceaccount "flannel" created configmap "kube-flannel-cfg" created daemonset "kube-flannel-ds" created

根据网络状况,安装过程需要一定的时间,最后要确保所有的Pod都处于Running状态。

稍等片刻,我们再来看master node上的cluster信息:

$ ps aux|grep kube|grep flannel root       718  0.0  1.5 252216 32176 ?        Ssl  15:25   0:00 /opt/bin/flanneld --ip-masq --kube-subnet-mgr root       758  0.0  0.0   8096  1880 ?        Ss   15:25   0:00 /bin/sh -c set -e -x; cp -f /etc/kube-flannel/cni-conf.json /etc/cni/net.d/10-flannel.conf; while true; do sleep 3600; done

检查各节点组件运行状态:

$ kubectl get pods --all-namespaces NAMESPACE     NAME                                    READY     STATUS              RESTARTS   AGE default       kube-flannel-ds-m556b                   2/2       Running             3          2h kube-system   dummy-2088944543-ctnqh                  1/1       Running             1          3h kube-system   etcd-dev-master-01                      1/1       Running             2          4h kube-system   kube-apiserver-dev-master-01            1/1       Running             1          4h kube-system   kube-controller-manager-dev-master-01   1/1       Running             1          4h kube-system   kube-discovery-1769846148-cpf2m         1/1       Running             0          8m kube-system   kube-dns-2924299975-8r4st               4/4       Running             0          3h kube-system   kube-proxy-hz20c                        1/1       Running             1          3h kube-system   kube-scheduler-dev-master-01            1/1       Running             1          4h

如果你非常想要知道它的状态及详细原因,对应你自己的NameSpace和Name把下面这条命令改一下,就可以看到详细信息了。常见的状态有RunContainerError,CrashLoopBackOff,ContainerCreating。

$ kubectl describe -n default  po kube-flannel-ds-m556b $ kubectl describe -n kube-system po kube-dns-2924299975-8r4st

验证是否部署成功

$ kubectl get nodes NAME            STATUS         AGE dev-master-01   Ready,master   5h

或者访问

$ curl http://127.0.0.1:8080 {  "paths": [    "/api",    "/api/v1",    ......    "/logs",    "/version"  ]

部署Kubernetes node

根据Master上初始化成功后会打印的token,把minion node加入cluster。(注意:这里要保证master node的9898端口在防火墙是打开的)

在minion node上执行

$ kubeadm join --token=e4f68e.6cc8c11c93148cd7 10.211.55.11 --skip-preflight-checks [kubeadm] WARNING: kubeadm is in alpha, please do not use it for production clusters. [preflight] Skipping pre-flight checks [tokens] Validating provided token [discovery] Created cluster info discovery client, requesting info from "http://10.211.55.11:9898/cluster-info/v1/?token-id=e4f68e" [discovery] Cluster info object received, verifying signature using given token [discovery] Cluster info signature and contents are valid, will use API endpoints [https://10.211.55.11:6443] [bootstrap] Trying to connect to endpoint https://10.211.55.11:6443 [bootstrap] Detected server version: v1.5.4 [bootstrap] Successfully established connection with endpoint "https://10.211.55.11:6443" [csr] Created API client to obtain unique certificate for this node, generating keys and certificate signing request [csr] Received signed certificate from the API server: Issuer: CN=kubernetes | Subject: CN=system:node:dev-node-01 | CA: false Not before: 2017-03-21 09:19:00 +0000 UTC Not After: 2018-03-21 09:19:00 +0000 UTC [csr] Generating kubelet configuration [kubeconfig] Wrote KubeConfig file to disk: "/etc/kubernetes/kubelet.conf" Node join complete: * Certificate signing request sent to master and response  received. * Kubelet informed of new secure connection details. Run 'kubectl get nodes' on the master to see this machine join.

验证是否加入成功

加入节点后,可以在master上验证下相关信息。

$ kubectl get nodes NAME            STATUS         AGE dev-master-01   Ready,master   5h dev-node-01     Ready          1m

上述这样以来基础环境就搭好了。不过只不过是万里长征第一步,折腾才刚刚开始而已。颤抖吧,少年!

一些小技巧

  • 由于使用kubeadm安装的kubernetes核心组件都是以docker容器的形式运行,如果安装过程出现问题,需要先执行下面的命令清理之前的执行残留后,才能重新开始。

kubeadm会自动检查当前环境是否有上次命令执行的“残留”。如果有,必须清理后再行执行init。我们可以通过”kubeadm reset”来清理环境,以备重来。

$ sudo kubeadm reset [preflight] Running pre-flight checks [reset] Stopping the kubelet service [reset] Unmounting mounted directories in "/var/lib/kubelet" [reset] Removing kubernetes-managed containers [reset] Deleting contents of stateful directories: [/var/lib/kubelet /etc/cni/net.d /var/lib/etcd] [reset] Deleting contents of config directories: [/etc/kubernetes/manifests /etc/kubernetes/pki] [reset] Deleting files: [/etc/kubernetes/admin.conf /etc/kubernetes/kubelet.conf]
  • 如果容器部署过程中失败,你非常想要知道它的状态及详细原因。可使用如下指令:

$ kubectl describe -n default  po kube-flannel-ds-m556b $ kubectl describe -n kube-system po kube-dns-2924299975-8r4st


参考文档






更多精彩热文:



您可能也对以下帖子感兴趣

文章有问题?点此查看未经处理的缓存